package br.com.faculdade.infrastructure.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 *
 * @author Kirmaier
 */
@Entity
@Table(name = "Reserva_Estadia")
//@NamedQueries({@NamedQuery(name = "ReservaEstadia.findAll", query = "SELECT r FROM ReservaEstadia r"), @NamedQuery(name = "ReservaEstadia.findByIdreserva", query = "SELECT r FROM ReservaEstadia r WHERE r.idreserva = :idreserva"), @NamedQuery(name = "ReservaEstadia.findByDatamarcacao", query = "SELECT r FROM ReservaEstadia r WHERE r.datamarcacao = :datamarcacao"), @NamedQuery(name = "ReservaEstadia.findByDatareserva", query = "SELECT r FROM ReservaEstadia r WHERE r.datareserva = :datareserva"), @NamedQuery(name = "ReservaEstadia.findByDatachegada", query = "SELECT r FROM ReservaEstadia r WHERE r.datachegada = :datachegada"), @NamedQuery(name = "ReservaEstadia.findByDatasaida", query = "SELECT r FROM ReservaEstadia r WHERE r.datasaida = :datasaida"), @NamedQuery(name = "ReservaEstadia.findByHospede", query = "SELECT r FROM ReservaEstadia r WHERE r.hospede = :hospede"), @NamedQuery(name = "ReservaEstadia.findByApartamento", query = "SELECT r FROM ReservaEstadia r WHERE r.apartamento = :apartamento"), @NamedQuery(name = "ReservaEstadia.findByRecepcionista", query = "SELECT r FROM ReservaEstadia r WHERE r.recepcionista = :recepcionista")})
public class ReservaEstadia implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "Id_reserva")
    private Integer idreserva;
    @Column(name = "Data_marcacao")
    @Temporal(TemporalType.DATE)
    private Date datamarcacao;
    @Column(name = "Data_reserva")
    @Temporal(TemporalType.DATE)
    private Date datareserva;
    @Column(name = "Data_chegada")
    @Temporal(TemporalType.DATE)
    private Date datachegada;
    @Column(name = "Data_saida")
    @Temporal(TemporalType.DATE)
    private Date datasaida;
    @Cascade({
        CascadeType.SAVE_UPDATE,
        CascadeType.PERSIST
    })
    @OneToOne(mappedBy = "reservaEstadia")
    private Lancamento lancamento;
    /**
     * Status possiveis da reserva
     * 0 = Reserva OK
     * 1 = Reservado
     * 2 = Hospedado
     */
    @Column(name = "Reserva")
    private Short reserva;
    @Cascade({
        org.hibernate.annotations.CascadeType.SAVE_UPDATE
    })
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumn(name = "Id_hospede", insertable = true, updatable = true, nullable = false)
    private Hospede hospede;
    @Cascade({
        org.hibernate.annotations.CascadeType.SAVE_UPDATE
    })
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JoinColumn(name = "Id_Apart", referencedColumnName = "Id_Apart", insertable = true, updatable = true, nullable = false)
    private Apartamento apartamento;

    public ReservaEstadia() {
    }

    public String getReservaDescricao() {
        if (reserva != null) {
            switch (reserva) {
                case 0:
                    return "OK";
                case 1:
                    return "Reservado";
                case 2:
                    return "Hospedado";
            }
        }
        return "";
    }

    public ReservaEstadia(Integer idreserva) {
        this.idreserva = idreserva;
    }

    public Integer getIdreserva() {
        return idreserva;
    }

    public void setIdreserva(Integer idreserva) {
        this.idreserva = idreserva;
    }

    public Date getDatamarcacao() {
        return datamarcacao;
    }

    public void setDatamarcacao(Date datamarcacao) {
        this.datamarcacao = datamarcacao;
    }

    public Date getDatareserva() {
        return datareserva;
    }

    public void setDatareserva(Date datareserva) {
        this.datareserva = datareserva;
    }

    public Date getDatachegada() {
        return datachegada;
    }

    public void setDatachegada(Date datachegada) {
        this.datachegada = datachegada;
    }

    public Date getDatasaida() {
        return datasaida;
    }

    public void setDatasaida(Date datasaida) {
        this.datasaida = datasaida;
    }

    public Hospede getHospede() {
        return hospede;
    }

    public void setHospede(Hospede hospede) {
        this.hospede = hospede;
    }

    public Apartamento getApartamento() {
        return apartamento;
    }

    public void setApartamento(Apartamento apartamento) {
        this.apartamento = apartamento;
    }

    public Short getReserva() {
        return reserva;
    }

    public void setReserva(Short reserva) {
        this.reserva = reserva;
    }

    public Lancamento getLancamento() {
        return lancamento;
    }

    public void setLancamento(Lancamento lancamento) {
        this.lancamento = lancamento;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idreserva != null ? idreserva.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ReservaEstadia)) {
            return false;
        }
        ReservaEstadia other = (ReservaEstadia) object;
        if ((this.idreserva == null && other.idreserva != null) || (this.idreserva != null && !this.idreserva.equals(other.idreserva))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.reservasis.ReservaEstadia[idreserva=" + idreserva + "]";
    }
}
